package com.hbnu.test.www.net;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class TCP_server05 {
    public static void main(String[] args) {
        try(ServerSocket serverSocket = new ServerSocket(8888);) {

            Socket socket = serverSocket.accept();
            InputStream in = socket.getInputStream();
            FileOutputStream fileOutputStream = new FileOutputStream(new File("D:\\软件\\tmp\\0001.jpeg"));
            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);

            int len = 0;
            byte[]bytes = new byte[1024];
            while((len = in.read(bytes))!=-1){
                fileOutputStream.write(bytes,0,len);
            }
            out.println("图片上传成功!");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
